package wwl.lsf.rabbitmq.controller;

import java.util.Random;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class ProduceMessage {

  @Autowired
  private AmqpTemplate amqpTemplate;

  @GetMapping("/rabbitmq")
  public String sendAMessage() {

    String msg = getRandomChinese();
    System.out.println(msg);

    this.amqpTemplate.convertAndSend("topic_exchange_test",
        "quick.orange.rabbit", msg);
    log.error("发送消息={}",msg);
    return msg;
  }
  public static String getRandomChinese() {
    return new String(new char[] { (char) (new Random().nextInt(20902) + 19968) });
  }

}
